﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SuperJ.CMS.ViewModels;
namespace SuperJ.CMS.Web.Areas.Admin.Controllers
{
    public class AnnounceController : BaseController
    {
        private SuperJ.CMS.Interfaces.Services.IAnnounceService announceService;
        // GET: /Announce/
        public AnnounceController(SuperJ.CMS.Interfaces.Services.IAnnounceService aService)
        {
            this.announceService = aService;
        }
        public ActionResult AnnounceList()
        {

            return View();
        }

        //
        // GET: /Announce/Details/5

        public ActionResult JsonAnnounceList()
        {
            //SuperJ.CMS.Models.CMSDBEntities cmse = new Models.CMSDBEntities();
            //cmse.SuperJ_Admin
            //List<Admin> admins = vipSignInDB.Admin.OrderByDescending(p => p.CreateTime).Skip((page - 1) * 10).Take(10).ToList();
            var t = new List<AnnounceViewModel>
            {
                new AnnounceViewModel{AnnounceId=1,Title="22222asdfdsaf",IsPass=true,IsTop=false,CreateTime=DateTime.Now.Date},
                new AnnounceViewModel{AnnounceId=2,Title="121212dsfs",IsPass=true,IsTop=false,CreateTime=DateTime.Now.Date},
                new AnnounceViewModel{AnnounceId=3,Title="22222asdfdsaf",IsPass=true,IsTop=false,CreateTime=DateTime.Now.Date},
                new AnnounceViewModel{AnnounceId=5,Title="22222asdfdsaf",IsPass=true,IsTop=false,CreateTime=DateTime.Now.Date},
                new AnnounceViewModel{AnnounceId=17,Title="22222asdfdsaf",IsPass=true,IsTop=false,CreateTime=DateTime.Now.Date}
            };
            //decimal c = vipSignInDB.Admin.Count();
            //var temp = new
            //{

            //    total = Math.Ceiling(c / 10m),
            //    page = page,
            //    records = admins.Count,
            //    rows = admins.Select(item => new { id = item.UserId, cell = new object[] { item.UserId, item.UserName, item.UserDept, item.IsPass, item.IsAdmin, item.LastLoginIp, item.LastLoginTime } })
            //};

            var temp=new
            {
                total=1,
            page=1,
            records=5,
            rows=t.Select(item=>new {AnnounceId=item.AnnounceId,cell=new object[] { item.AnnounceId,item.Title,item.IsTop,item.IsTop,item.IsPass,item.CreateTime }})
            };
            
            return Json(temp, JsonRequestBehavior.AllowGet);
            
        }

        //
        // GET: /Announce/Create
        [HttpPost]
        public ActionResult AnnounceForm(AnnounceViewModel avm)
        {
            ViewBag.TabCounter = this.TabCounter;
            announceService.Create(avm);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult AnnounceForm()
        {
            //tabCounter = Request.QueryString["tc"].ToString();
            //Response.AppendHeader("TabCounter", "12");
            ViewBag.TabCounter = this.TabCounter;
            //ViewBag.TabCounter = tc;
            return View();
        }

        //
        // POST: /Announce/Create

        [HttpPost]
        public ActionResult Create(SuperJ.CMS.ViewModels.AnnounceViewModel announce)
        {
            try
            {
                //announceService
                //announceService.Create(announce);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Announce/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Announce/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Announce/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Announce/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
